package com.anke.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.anke.dao.ManagerDao;
import com.anke.entity.Company;
import com.anke.entity.Manager;
import com.anke.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = ManagerService.class)
@Transactional
public class ManagerServiceImpl implements ManagerService{
    @Autowired
    private ManagerDao managerDao;

    @Override
    public boolean login(Manager manager) {
        List<Manager> m = managerDao.login(manager);
        return !m.isEmpty();
    }

    @Override
    public void addUser(User user) {
        managerDao.addUser(user);
    }

    @Override
    public void deleteUser(User user) {
        managerDao.deleteUserById(user);
    }

    @Override
    public boolean updateUser(User user) {
        int u = managerDao.updateUser(user);
        if (u > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<User> selectUser() {
        return managerDao.selectAllUser();
    }

    @Override
    public void addCompany(Company company) {
        managerDao.addCompany(company);
    }

    @Override
    public void deleteCompany(Company company) {
        managerDao.deleteCompanyById(company);
    }

    @Override
    public boolean updateCompany(Company company) {
        int u = managerDao.updateCompany(company);
        if (u > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<Company> selectCompany() {
        return managerDao.selectAllCompany();
    }
}
